<template>
  <el-dropdown trigger="click" @command="changeLanguage">
    <div>
      <svg-icon class="icon" icon-class="language" />
    </div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item command="zh" :disabled="$i18n.locale === 'zh'">中文</el-dropdown-item>
      <el-dropdown-item command="en" :disabled="$i18n.locale === 'en'">EN</el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
import Cookies from 'js-cookie' // 引入cookie包
export default {
  methods: {
    changeLanguage(lang) {
      // 修改当前项目的语言环境
      this.$i18n.locale = lang
      // 把语言环境持久化到本地
      Cookies.set('language', lang)
      this.$message.success('语言环境切换成功')
      //  window.location.reload()
      // 把语言环境存储到vuex
      this.$store.commit('settings/CHANGE_SETTING', { key: 'language', value: lang })
    }
  }
}
</script>

<style lang="scss" scoped>
.icon {
  width: 25px !important;
  height: 25px !important;
  fill: red !important;
  cursor: pointer;
}
</style>
